package com.xujie.sportsmeeting.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xujie.sportsmeeting.entity.EventJudge;
import com.xujie.sportsmeeting.entity.Judge;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 项目裁判员关联 Mapper 接口
 */
@Mapper
public interface EventJudgeMapper extends BaseMapper<EventJudge> {

    /**
     * 根据项目ID查询分配的裁判员列表
     */
    @Select("SELECT j.* FROM judge j " +
            "INNER JOIN event_judge ej ON j.id = ej.judge_id " +
            "WHERE ej.event_id = #{eventId} " +
            "ORDER BY ej.judge_role ASC, ej.assign_time ASC")
    List<Judge> selectJudgesByEventId(@Param("eventId") Long eventId);

    /**
     * 根据裁判员ID查询分配的项目列表
     */
    @Select("SELECT ce.* FROM competition_event ce " +
            "INNER JOIN event_judge ej ON ce.id = ej.event_id " +
            "WHERE ej.judge_id = #{judgeId} " +
            "ORDER BY ej.assign_time ASC")
    List<com.xujie.sportsmeeting.entity.CompetitionEvent> selectEventsByJudgeId(@Param("judgeId") Long judgeId);
}
